/**
 * MarioEnemy_FirePiranhaPlantAI
 * @extends MarioAI_Patrol
 * @version 2010.12.03
 */

class MarioEnemy_FirePiranhaPlantAI extends AIController;

var float attackDistance;
var int attackDamage;
var float perceptionDistance;
var float distanceToPlayer;
var bool AttAcking;
var bool followingPath;
var bool noiseHeard;
var Float IdleInterval;

var MarioEnemy_FirePiranhaPlant MyPawn;
var Pawn thePlayer;

/**
 * ThrowWeaponOnDeath - does this need to be here?
 * @version 2010.12.03
 */
function ThrowWeaponOnDeath() { }

/**
 * SetPawn
 * @version 2010.12.03
 */
function SetPawn(MarioEnemy_FirePiranhaPlant NewPawn)
{
    MyPawn = NewPawn;
	Possess(MyPawn, false);
}

/**
 * Possess
 * @version 2010.12.03
 */
function Possess(Pawn aPawn, bool bVehicleTransition)
{
    if (aPawn.bDeleteMe)
	{
		`Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
		 ScriptTrace();
		 GotoState('Dead');
    }
	else
	{
		Super.Possess(aPawn, bVehicleTransition);

		Pawn.SetPhysics(PHYS_None);
	}
}

state Dead
{
	Begin:
		Pawn.Destroy();
}

defaultproperties
{
	actual_node = 0
	last_node   = 0

	followingPath = true
	IdleInterval  = 2.5f
	AttAcking = false;

	attackDistance = 50
    attackDamage = 10
    perceptionDistance = 1000
}

state FollowPath{
Begin:
}

state Idle
{

    event SeePlayer(Pawn SeenPlayer)
	{
	    thePlayer = SeenPlayer;
        distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer < attackDistance)
        { 
        	//Worldinfo.Game.Broadcast(self, "I can see you!!");
            //GotoState('Attack');
			GotoState('Jump');

        }
    }

Begin:
	Acceleration = vect(0,0,0);
	Velocity.X = 0;
	Velocity.Y = 0;
    Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");

	//MyPawn.SetAttacking(false);

	Sleep(IdleInterval);

	followingPath = true;
	GotoState('Jump');

}

state Attack
{
 Begin:
	Acceleration = vect(0,0,0);
	Velocity.X = 0;
	Velocity.Y = 0;
	//MyPawn.SetAttacking(true);
	/*while(true && thePlayer.Health > 0)
	{   
		//Worldinfo.Game.Broadcast(self, "Attacking Player");

		distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer > attackDistance)
        { 
			MyPawn.SetAttacking(false);
            GotoState('Idle');
			break;
        }
		Sleep(1);
	}*/
	//MyPawn.SetAttacking(false);
	GotoState('Jump');
}

auto state Jump
{
	/*event SeePlayer(Pawn SeenPlayer)
	{
	    thePlayer = SeenPlayer;
        distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
        if (distanceToPlayer < attackDistance)
        { 
        	//Worldinfo.Game.Broadcast(self, "I can see you!!");
			followingPath = false;
            GotoState('Attack');
        }
    }*/

 Begin:
	Acceleration = vect(0,0,0);
	Velocity.X = 0;
	Velocity.Y = 0;

	//while(followingPath)
	//{
		Pawn.DoJump(FALSE);

		Sleep(1);

	//}
}

